<template>
  <div>
    <div class="video-card" @click.stop="rowClick">
      <div class="video-id cl-gruy3 ths-font">{{ computeId(videoData.videoId) }}</div>
      <div class="video-discribe">
        <div class="discribe-title">
          <span class="discribe-title-text">{{ videoData.title }}</span>
          <div class="video-span cl-r" v-if="+videoData.free === 0 && !auth">免费试学</div>
        </div>
        <div class="discribe-time mt-16 cl-gruy2">{{ videoData.duration }}</div>
      </div>
      <div class="video-icon">
        <!-- 播放中 -->
        <div class="icon active-playing" v-if="playing">
          <i class="innerShort bg-r mr-10"></i>
          <i class="innerLong bg-r mr-10"></i>
          <i class="innerShort bg-r"></i>
        </div>
        <!-- 无权限 -->
        <div class="icon icon-lock-course" v-else-if="!auth && +videoData.free === 1"></div>
        <!-- 可播放 -->
        <div class="icon icon-play" v-else></div>
      </div>
    </div>
  </div>
</template>

<script>
export default {
  name: 'VideoCardPlay',
  components: {},
  props: {
    auth: {
      type: Boolean,
      default: false,
    },
    videoData: {
      type: Object,
    },
    currentIndex: {
      type: Number,
    },
  },
  computed: {
    playing({ currentIndex, videoData }) {
      return Number(currentIndex) === Number(videoData.videoId);
    },
  },
  data() {
    return {
      classProgress: 13,
    };
  },
  methods: {
    computeId(num) {
      const decimal = 10;
      if (!num) {
        return '';
      } else {
        const a = Number(num);
        if (a < decimal) {
          return `0${a}`;
        } else {
          return String(a);
        }
      }
    },
    rowClick() {
      this.$emit('play', '');
    },
  },
};
</script>

<style lang="less" scoped>
.icon-lock-course {
  background: url('../../assets/images/lock.svg') no-repeat;
  background-size: 100% 100%;
}
.video-card {
  position: relative;
  display: flex;
  justify-content: space-between;
  padding: 0.3rem 0;
  .theme-mixins(border-bottom, 1px solid #eeeeee, 1px solid #222222);
}
.video-id {
  width: 0.48rem;
  height: 0.36rem;
  font-size: 0.3rem;
  line-height: 0.38rem;
}
.video-discribe {
  display: flex;
  flex-direction: column;
  flex: 1;
  .discribe-title {
    display: flex;
    height: 0.36rem;
    font-size: 0.3rem;
    line-height: 0.36rem;
    font-weight: bold;
    max-width: 5.8rem;
    .discribe-title-text {
      overflow: hidden;
      text-overflow: ellipsis;
      white-space: nowrap;
    }
    .video-span {
      background: rgba(233, 48, 48, 0.1);
      border-radius: 0.04rem;
      font-size: 0.24rem;
      height: 0.36rem;
      margin-left: 0.16rem;
      padding: 0 0.08rem;
      flex-shrink: 0;
    }
  }
  .discribe-time {
    height: 0.3rem;
    font-size: 0.24rem;
    line-height: 0.3rem;
  }
}
.video-icon {
  display: flex;
  align-items: center;
  .icon {
    width: 0.44rem;
    height: 0.44rem;
  }
  .active-playing {
    width: 0.44rem;
    height: 0.44rem;
    display: flex;
    align-items: center;
    justify-content: center;
    .innerLong {
      width: 0.05rem;
      height: 0.32rem;
      border-radius: 0.03rem;
      display: block;
      animation: live1 0.8s infinite linear;
      -webkit-animation: live1 0.8s infinite linear;
    }
    .innerShort {
      width: 0.05rem;
      height: 0.18rem;
      border-radius: 0.03rem;
      display: block;
      animation: live2 0.8s infinite linear;
      -webkit-animation: live2 0.8s infinite linear;
    }
  }
}
@keyframes live1 {
  0% {
    height: 0.32rem;
  }

  50% {
    height: 0.18rem;
  }

  100% {
    height: 0.32rem;
  }
}
@-webkit-keyframes live1 {
  0% {
    height: 0.32rem;
  }

  50% {
    height: 0.18rem;
  }

  100% {
    height: 0.32rem;
  }
}
@keyframes live2 {
  0% {
    height: 0.18rem;
  }

  50% {
    height: 0.32rem;
  }

  100% {
    height: 0.18rem;
  }
}
@-webkit-keyframes live2 {
  0% {
    height: 0.18rem;
  }

  50% {
    height: 0.32rem;
  }

  100% {
    height: 0.18rem;
  }
}
</style>
